package com.donleo.mp.generator.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.donleo.mp.generator.common.CommonResult;
import com.donleo.mp.generator.model.User;
import com.donleo.mp.generator.service.UserService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.kafka.KafkaProperties;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 后台用户表 前端控制器
 * </p>
 *
 * @author liangd
 * @since 2020-12-16
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/query")
    public CommonResult<IPage> getById(@RequestBody User user) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.lambda().like(StringUtils.isNotBlank(user.getUsername()), User::getUsername, user.getUsername());
        IPage<User> page = new Page<>(1, 2);
        IPage<User> iPage = userService.page(page, wrapper);
        return CommonResult.success(iPage);
    }

    @GetMapping("/findAll")
    public CommonResult findAll(){
        List<User> list = userService.list(null);
        return CommonResult.success(list);
    }
}
